package com.sensetime.jv.controller;

import com.sensetime.jv.annotation.RequirePermission;
import com.sensetime.jv.entity.ReturnWrapper;
import com.sensetime.jv.service.RoleService;
import com.sensetime.jv.vo.RoleRespVO;
import com.sensetime.jv.vo.RoleSaveReqVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
public class RoleController {

    private final RoleService roleService;

    @GetMapping("/list")
    @RequirePermission(description = "查询角色")
    public ReturnWrapper<List<RoleRespVO>> list() {
        return ReturnWrapper.success(roleService.listAll());
    }

    @GetMapping("/{id}")
    @RequirePermission(description = "获取单个角色权限")
    public ReturnWrapper<RoleRespVO> detail(@PathVariable Integer id) {
        return ReturnWrapper.success(roleService.detail(id));
    }

    @PostMapping
    @RequirePermission(description = "插入或者更新角色权限")
    public ReturnWrapper<Void> save(@Valid @RequestBody RoleSaveReqVO vo) {
        roleService.saveOrUpdate(vo);
        return ReturnWrapper.success();
    }

    @DeleteMapping("/{id}")
    @RequirePermission(description = "删除角色权限")
    public ReturnWrapper<Void> remove(@PathVariable Integer id) {
        roleService.removeById(id);
        return ReturnWrapper.success();
    }
}